package com.platform.qujia.utils;

import java.math.BigDecimal;

/**
 * @date 2023/9/22
 */
public class MathUtil {

    public static BigDecimal add(BigDecimal a, BigDecimal b){
        if (a==null && b == null) {
            return BigDecimal.ZERO;
        }else if(a == null){
            return b;
        }else if(b == null){
            return a;
        }else{
            return a.add(b);
        }
    }


    public static BigDecimal subtract(BigDecimal a,BigDecimal subtrahend){
        if (a==null && subtrahend == null) {
            return BigDecimal.ZERO;
        }else if(a == null){
            return subtrahend;
        }else if(subtrahend == null){
            return a;
        }else{
            return a.subtract(subtrahend);
        }
    }

    public static Long add(Long a,Long b){
        if (a==null && b == null) {
            return 0L;
        }else if(a == null){
            return b;
        }else if(b == null){
            return a;
        }else{
            return a+b;
        }
    }

    public static Long subtract(Long a,Long subtrahend){
        if (a==null && subtrahend == null) {
            return 0L;
        }else if(a == null){
            return subtrahend;
        }else if(subtrahend == null){
            return a;
        }else{
            return a-subtrahend;
        }
    }

    public static Integer add(Integer a,Integer b){
        if (a==null && b == null) {
            return 0;
        }else if(a == null){
            return b;
        }else if(b == null){
            return a;
        }else{
            return a+b;
        }
    }


    public static Integer subtract(Integer a,Integer subtrahend){
        if (a==null && subtrahend == null) {
            return 0;
        }else if(a == null){
            return subtrahend;
        }else if(subtrahend == null){
            return a;
        }else{
            return a-subtrahend;
        }
    }

    public static Long toLong(Integer a){
        return toLong(a,null);
    }

    public static Long toLong(Integer a,Long defValue){
        if(a==null){
            return defValue;
        }else{
            return a.longValue();
        }
    }

    public static Integer toInt(Long a){
        return toInt(a,null);
    }

    public static Integer toInt(Long a, Integer defValue){
        if(a == null){
            return defValue;
        }else{
            return a.intValue();
        }
    }
}
